package veterinaria.servlet.dueno;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.negocio.GestionDueno;

/**
 * Servlet implementation class DuenoInsertarServlet
 */
@WebServlet("/DuenoInsertarServlet")
public class DuenoInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DuenoInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		

		GestionDueno negocio = new GestionDueno();
		
		String 	nombre = request.getParameter("nombre");
		String 	paterno = request.getParameter("paterno");
		String 	materno = request.getParameter("materno");
		String 	email = request.getParameter("email");
		String 	direccion = request.getParameter("direccion");
		String 	imagen = request.getParameter("imagen");
		String 	telefono = request.getParameter("telefono");
		String 	celular = request.getParameter("celular");
		String 	rucdni = request.getParameter("rucdni");
		
		try {
			negocio.insertar(nombre,paterno,materno,email,direccion,imagen,telefono,celular,rucdni);
			response.sendRedirect(request.getContextPath()	+ "/DuenoBuscarServlet");
		} catch (DAOExcepcion e) {
			request.setAttribute("ERRORES", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("dueno_nuevo.jsp");
			rd.forward(request, response);
		}
		
	}

}
